package Q2;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[][] arr = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int q = scanner.nextInt();
        while (q > 0) {
            q--;
            int x = scanner.nextInt();
            switch (x) {
                case 1:
                    //将矩阵顺时针旋转 180 度
                    for (int i = 0; i < n - 1; i++) {
                        for (int j = 0; j < n - i; j++) {
                            swap(arr, i, j, n - 1- i, n - 1 - j);
                        }
                    }
                    break;
                case 2:
                    //将矩阵按行进行翻转
                    for (int i = 0; i < n / 2; i++) {
                        for (int j = 0; j < n; j++) {
                            swap(arr, i, j, n - 1 - i, j);
                        }
                    }
                    break;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static void swap(int[][] arr, int i1, int j1, int i2, int j2) {
        int temp = arr[i1][j1];
        arr[i1][j1] = arr[i2][j2];
        arr[i2][j2] = temp;
    }
}
